11. Solution: Argument Matchers
Solution: Argument Matchers
ND079 JPND C3 L5 A07 Solution Argument Matchers
Add Dependency
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.6.0</version>
<scope>test</scope>
</dependency>
Update Test Class
@ExtendWith(MockitoExtension.class)
class TimeZoneServiceTest {
private TimeZoneService timeZoneService;
@Mock
private WorldTimeApiClient worldTimeApiClient;
@BeforeEach
void init() {
timeZoneService = new TimeZoneService(worldTimeApiClient);
}
@Test
void getAvailableTimezoneText_timeApiReturnsStringList_returnsCountriesAsString() {
List<String> validTimeZones = List.of("Amsterdam", "Andorra", "Astrakhan", "Athens");
when(worldTimeApiClient.getValidTimeZones(anyString())).thenReturn(validTimeZones);
String expectedReturn = "Amsterdam, Andorra, Astrakhan, Athens";
String availableTimezoneText = timeZoneService.getAvailableTimezoneText("Europe");
assertTrue(availableTimezoneText.contains(expectedReturn));
}
}